/**
 * Created by Administrator on 2018/5/9.
 */
import React from 'react'
import {
  Redirect
} from 'react-router-dom'
import { connect } from 'react-redux'
import { login,getUserData } from './Auth.redux.js'
class Auth extends React.Component{
   componentDidMount(){
     this.props.getUserData()
   }
   render(){
     return (
         <div>
           <h1>{this.props.name}</h1>
           <h1>{this.props.age}</h1>
           { this.props.isAuth?<Redirect to="/dashdoard"></Redirect>:null}
            <h1>没有权限</h1>
           <button onClick={this.props.login}>登录</button>
         </div>
     )
   }
}

const mapStatetoProps =(state)=>{
  return state.auth
}

const actionCreators = {login,getUserData}
Auth = connect(mapStatetoProps,actionCreators)(Auth)
export default Auth